﻿
using System;
using System.Data;
using System.Collections.Generic;

namespace LDSP.BRL
{
    /// <summary>
    /// 栏目企业授权关系
    /// </summary>
    public partial class R_EnterpriseCatalog : BYFW.BOL.BaseEntity
    {
        public R_EnterpriseCatalog()
        {
            m_tableName = "t_r_enterprise_catalog";
            m_tblCacheManager.IsEnable = true;
            m_objCacheManager.Size = 1000;
        }

        protected int m_enterpriseID = 0;
        protected int m_catalogID = 0;
        protected int m_sequence = 0;
        protected Enterprise m_enterprise = null;
        protected Catalog m_catalog = null;

        /// <summary>
        /// 
        /// </summary>
        public int EnterpriseID
        {
            get { return m_enterpriseID; }
            set { m_enterpriseID = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public int CatalogID
        {
            get { return m_catalogID; }
            set { m_catalogID = value; }
        }

        /// <summary>
        /// 顺序
        /// </summary>
        public int Sequence
        {
            get { return m_sequence; }
            set { m_sequence = value; }
        }

        public Enterprise Enterprise
        {
            get
            {
                if (m_enterprise == null)
                {
                    m_enterprise = new Enterprise();
                    if (m_enterpriseID != 0)
                    {
                        m_enterprise.GetProperties(m_enterpriseID);
                    }
                }
                return m_enterprise;
            }
        }

        public Catalog Catalog
        {
            get
            {
                if (m_catalog == null)
                {
                    m_catalog = new Catalog();
                    if (m_catalogID != 0)
                    {
                        m_catalog.GetProperties(m_catalogID);
                    }
                }
                return m_catalog;
            }
        }

        protected override void FillContainer()
        {
            base.FillContainer();
            m_container.Add("enterpriseID", m_enterpriseID);
            m_container.Add("catalogID", m_catalogID);
            m_container.Add("sequence", m_sequence);
        }

        public override bool GetProperties(System.Data.DataRow record)
        {
            if (!base.GetProperties(record))
            {
                return false;
            }
            m_enterpriseID = this.GetIntValue(record, "enterpriseID");
            m_catalogID = this.GetIntValue(record, "catalogID");
            m_sequence = this.GetIntValue(record, "sequence");
            return true;
        }

        public List<R_EnterpriseCatalog> GetListByEnterpriseID(int enterpriseID)
        {
            return this.GetSpecialList<R_EnterpriseCatalog>(null, string.Format("where {0}={1} order by sequence", DB.GetCol("enterpriseID"), DB.GetVal(enterpriseID)));
        }

        public void DeleteByEnterprise(string transID, int enterpriseID)
        {
            string cond = string.Format("where {0}={1}", DB.GetCol("enterpriseID"), DB.GetVal(enterpriseID));
            this.DeleteRecord(transID, cond);
        }

        public void DeleteByEnterpriseAndCatalog(string transID, int enterpriseID, int catalogID)
        {
            string cond = string.Format("where {0}={1} and {2}={3}", DB.GetCol("enterpriseID"), DB.GetVal(enterpriseID), DB.GetCol("catalogID"), DB.GetVal(catalogID));
            this.DeleteRecord(transID, cond);
        }

        public void DeleteByCatalog(string transID, int catalogID)
        {
            string cond = string.Format("where {0}={1}", DB.GetCol("catalogID"), DB.GetVal(catalogID));
            this.DeleteRecord(transID, cond);
        }
    }
}
